﻿#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    sql=new mySql;
    sql->openBase();
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    QString command_2="DROP TABLE cityCode";
    sql->commonFuc(command_2);
    QString comand_1="CREATE TABLE IF NOT EXISTS cityCode(\
            code TEXT,\
            city TEXT)";
            sql->commonFuc(comand_1);
    QFile fp("D:\\QT\\QTproject\\practice_0626\\try_1\\city.txt");
    if(fp.open(QIODevice::ReadOnly|QIODevice::Text))
    {
        QTextStream all(&fp);
        all.setCodec("UTF-8");
        while(!all.atEnd())
        {
            QString line=all.readLine();
            QStringList list=line.split(QChar('\t'));
            if(list.size()==2)
            {
                QString code=list.value(0);
                QString city=list.value(1);
                QString command=QString("INSERT INTO cityCode VALUES('%1','%2')").arg(code).arg(city);
                sql->commonFuc(command);
            }
        }
        fp.close();
    }


    //    QString comand="CREATE TABLE IF NOT EXISTS cityCode(\
    //                   city TEXT,\
    //                   code TEXT)";
    //    sql->commonFuc(comand);
    //    QString comand_2=QString("INSERT INTO cityCode VALUES('%1','%2')").arg("北京").arg("10101010");
    //    sql->commonFuc(comand_2);

}
